import BaseComponent from "../../redare/components/BaseComponent";
import {PageHeader} from "antd";
import {Link} from "react-router-dom";
import React from "react";

export default class CommonPageHeader extends BaseComponent {

    static defaultProps = {
        routes:[],
        className:undefined,
        title:undefined,
        onBack:undefined
    };

    itemRender(route, params, routes, paths){
        const last = routes.indexOf(route) === routes.length - 1;
        let {path} = route;
        return last ? (
            <span>{route.breadcrumbName}</span>
        ) : (
            <Link to={`${path}`}>{route.breadcrumbName}</Link>
        );
    }

    render(){
        let {routes} = this.props;
        return (
            <PageHeader {...this.props}
                        breadcrumb={{routes:routes,itemRender:this.itemRender.bind(this)}}/>
        )
    }
}